﻿using System.Collections.Generic;
using System.Linq;
using NHibData;
using StudyEnglish.Model;

namespace StudyEnglish.Models
{
    public class DictionaryModel
    {
        public IList<TypedDictionary> Dictionaries = new List<TypedDictionary>();
        public DictionaryModel(IList<DictionaryItem> allItems)
        {
            Levels = new TypedDictionary(allItems, EDictType.Level, "Levels");
            Categories = new TypedDictionary(allItems, EDictType.Category, "Categories");
            SubCategories = new TypedDictionary(allItems, EDictType.SubCategory, "Subcategories");
            Topics = new TypedDictionary(allItems, EDictType.Topic, "Topics");
            Types = new TypedDictionary(allItems, EDictType.Type, "Types");

            Dictionaries.Add(Levels);
            Dictionaries.Add(Categories);
            Dictionaries.Add(SubCategories);
            Dictionaries.Add(Topics);
            Dictionaries.Add(Types);
        }

        public class TypedDictionary
        {
            public IList<DictionaryItem> Items;
            public EDictType DictType;
            public string Name;

            public TypedDictionary(IEnumerable<DictionaryItem> items, EDictType type, string name )
            {
                Items = items.Where(x => x.DictType == type).OrderBy(x=>x.Name).ToList();
                DictType = type;
                Name = name;
            }
        }
        public TypedDictionary Levels;
        public TypedDictionary Categories;
        public TypedDictionary SubCategories;
        public TypedDictionary Topics;
        public TypedDictionary Types;
    }
}